package com.code.day02.dao;

import com.code.day02.utils.ConnectionManager;
import com.code.day02.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.SQLException;

public class AccountDao {

    public void outMoney(String outname, int money) throws SQLException{
        QueryRunner queryRunner = new QueryRunner();
        String sql = "update account set money=money-? where name=?";
        queryRunner.update(ConnectionManager.getConnection(), sql, money, outname);
    }

    public void inMoney(String inname, int money) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        Connection connection = DruidUtils.getConnection();
        String sql = "update account set money=money+? where name=?";
        queryRunner.update(ConnectionManager.getConnection(), sql, money, inname);
    }
}
